package com.sz.youban.manage.common;

import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

@Configuration
public class ScheduledListener  implements ApplicationListener<ContextRefreshedEvent>
{
	private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledListener.class);
	@Autowired
	private PaySchedule paySchedule;
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) 
	{
		 try 
		 { 
			 paySchedule.scheduleJobs(); 
		 } 
		 catch (SchedulerException e) 
		 { 
			 LOGGER.error("==========SchedulerException is {}",e);
		 }
	}
	
	@Bean
	public SchedulerFactoryBean schedulerFactoryBean()
	{
		SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); 
		return schedulerFactoryBean; 
	}
}
